package net.yuxianghe.chromepool;

import com.google.gson.Gson;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.Date;
import java.util.UUID;

/**
 * ChromeDriverObject
 * Created by hxy on 2017/5/21.
 */
public class ChromeDriverObject implements Comparable {

    private String uuid = UUID.randomUUID().toString();

    private ChromeDriver chromeDriver;

    private boolean runStatus;

    private Date startTime;

    private Date endTime;

    private int aliveTime;


    public ChromeDriver getChromeDriver() {
        return chromeDriver;
    }

    public void setChromeDriver(ChromeDriver chromeDriver) {
        this.chromeDriver = chromeDriver;
    }

    public boolean isRunStatus() {
        return runStatus;
    }

    public void setRunStatus(boolean runStatus) {
        this.runStatus = runStatus;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public int getAliveTime() {
        return aliveTime;
    }

    public void setAliveTime(int aliveTime) {
        this.aliveTime = aliveTime;
    }

    @Override
    public int hashCode() {
        return this.hashCode();
    }


    @Override
    public boolean equals(Object obj) {
        ChromeDriverObject chromeDriverObject = (ChromeDriverObject) obj;
        return this.uuid.equals(chromeDriverObject.getUuid());
    }

    @Override
    public int compareTo(Object o) {
        ChromeDriverObject chromeDriverObject = (ChromeDriverObject) o;
        long temp = this.startTime.getTime() - chromeDriverObject.getStartTime().getTime();
        if (temp > 0) {
            return 1;
        } else if (temp < 0) {
            return -1;
        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}
